package dao

import (
	"ssims/models"
)

func GetAllStudent(student map[string]interface{}) (error, []models.Student, int64) {
	var studentData []models.Student
	page := student["page"].(int)
	pageSize := student["limit"].(int)
	//searchStudentName := student["searchStudentame"].(string)
	var total int64
	err := db.Table("student").Select("student_no, student_name, student_sex, student_time, student_area, student_age, political_landscape, student_national, dept_name, update_time").Where("is_del = false").Order("student_no ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&studentData).Error
	return err, studentData, total
}
func GetNumbers(student map[string]interface{}) (error, []models.Tji, int64) {
	var numbersDate []models.Tji
	// page := sc["page"].(int)
	// pageSize := sc["limit"].(int)
	//searchName := sc["searchNo"].(int)
	var total int64
	err := db.Table("student").Select("student_area, COUNT(student_area)").Group("student_area").Count(&total).Find(&numbersDate).Error
	return err, numbersDate, total
}
func DelStudent(id string) error {
	err := db.Table("student").Where("student_no = ?", id).Update("is_del", true).Error
	return err
}
func GetNumbera(student map[string]interface{}) (error, []models.Tji, int64) {
	var numbersDate []models.Tji
	// page := sc["page"].(int)
	// pageSize := sc["limit"].(int)
	//searchName := sc["searchNo"].(int)
	var total int64
	err := db.Table("student").Select("student_age, COUNT(student_age)").Group("student_age").Count(&total).Find(&numbersDate).Error
	return err, numbersDate, total
}
func GetNumberp(student map[string]interface{}) (error, []models.Tji, int64) {
	var numbersDate []models.Tji
	// page := sc["page"].(int)
	// pageSize := sc["limit"].(int)
	//searchName := sc["searchNo"].(int)
	var total int64
	err := db.Table("student").Select("political_landscape, COUNT(political_landscape)").Group("political_landscape").Count(&total).Find(&numbersDate).Error
	return err, numbersDate, total
}
func UpdateStudent(student models.Student) error {
	err := db.Table("student").Where("student_no = ?", student.StudentNo).Updates(&student).Error
	return err
}

func AddStudent(student models.Student) error {
	err := db.Table("student").Select("student_no", "student_name", "student_sex", "student_time", "student_area", "student_age", "political_landscape", "student_national", "dept_name", "update_time", "is_del").Create(&student).Error
	return err
}
